Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jj git push: safety checks when pushing branch sideways, similar to git push --force-with-lease #3522

Merged
merged 8 commits into from
May 29, 2024

Conversation

ilyagr
Copy link
Collaborator

@ilyagr ilyagr commented Apr 17, 2024

Previously, jj git push only made sure that the branch is in the expected
location on the remote server when pushing a branch forward (as opposed to
sideways or backwards). Now, jj git push makes a safety check in all cases
and fails whenever jj git fetch would have introduced a conflict.

In other words, previously branches that moved sideways or backward were
pushed similarly to Git's git push --force; now they have protections
similar to git push --force-with-lease (though not identical to it, to match
the behavior of jj git fetch). Note also that because of the way jj git fetch works, jj does not suffer from the same problems as Git's git push --force-with-lease in situations when git fetch is run in the background.


There are a few TODOs that may be added later (in this or separate PRs):

  • Document this behavior in jj help git push, possibly elsewhere.
  • Adjustments to user-facing UI
  • Additional tests

See TODOs in the code for more details. It's possible I forgot some, but it's probably time for others to look at the general form of this PR in any case.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • (n/a) I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@ilyagr ilyagr force-pushed the force-with-lease branch 8 times, most recently from 64c74f3 to 2d13e97 Compare April 18, 2024 21:13
lib/src/git.rs Outdated Show resolved Hide resolved
lib/src/git.rs Outdated Show resolved Hide resolved
@ilyagr ilyagr force-pushed the force-with-lease branch 6 times, most recently from 81b11aa to f7cec4f Compare April 20, 2024 06:51
@ilyagr ilyagr force-pushed the force-with-lease branch from f7cec4f to 61e5cd1 Compare May 2, 2024 05:15
@ilyagr ilyagr force-pushed the force-with-lease branch 13 times, most recently from 8b7e930 to bb9547c Compare May 12, 2024 00:06
@ilyagr ilyagr force-pushed the force-with-lease branch 2 times, most recently from e1511cf to f056679 Compare May 26, 2024 02:27
@ilyagr
Copy link
Collaborator Author

ilyagr commented May 26, 2024

This should be ready for review again.

Apart from addressing the comments, I added a commit for adjusting jj git push's user-facing messages. I also removed the refactor of NotFastForward, since we delete it anyway.

@ilyagr ilyagr marked this pull request as ready for review May 26, 2024 02:32
Copy link
Collaborator

@yuja yuja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, thanks!

lib/src/git.rs Outdated Show resolved Hide resolved
cli/src/commands/git.rs Outdated Show resolved Hide resolved
lib/src/git.rs Outdated Show resolved Hide resolved
lib/src/git.rs Outdated Show resolved Hide resolved
lib/src/git.rs Outdated Show resolved Hide resolved
lib/src/git.rs Outdated Show resolved Hide resolved
cli/src/commands/git.rs Outdated Show resolved Hide resolved
@ilyagr ilyagr force-pushed the force-with-lease branch 5 times, most recently from c4d8ee4 to eb6ba74 Compare May 27, 2024 02:54
@ilyagr ilyagr force-pushed the force-with-lease branch from eb6ba74 to b773c18 Compare May 27, 2024 03:40
ilyagr added 5 commits May 27, 2024 11:11
Adds two tests where pushing should fail, but currently succeeds.
This tests `git push` attempting to create a branch when the branch
already unexpectedly exists on the remote. This should (and does)
fail.

Also changes another test to use `jj_cmd_failure`.
The new names are a bit clearer. Soem tests already use a
`sideways_commit`, `parent_of_main_commit` will be needed in
an upcoming test.
Hopefully, splitting the no-op portion will make the following commits
easier to review.
As explained in the commit, our logic is a bit more complicated than
that of `git push --force-with-lease`. This is to match the behavior of
`jj git fetch` and branch conflict resolution rules.
@ilyagr ilyagr force-pushed the force-with-lease branch from b773c18 to 1daeaf8 Compare May 27, 2024 18:12
ilyagr added 3 commits May 28, 2024 19:15
This should be a no-op, though that is not necessarily obvious in corner
cases.

Note that libgit2 already performs the push negotiation even when
pushing without force (without `+` in the refspec).
Now that we always force push, it should not occur in practice.
@ilyagr ilyagr force-pushed the force-with-lease branch from 1daeaf8 to 7dc8026 Compare May 29, 2024 02:15
@ilyagr
Copy link
Collaborator Author

ilyagr commented May 29, 2024

Thank you Yuya for the review! I plan to merge this tomorrow if I don't hear otherwise. If I hear from you earlier, I might merge it then.

@ilyagr ilyagr merged commit e3bb825 into jj-vcs:main May 29, 2024
16 checks passed
@ilyagr ilyagr deleted the force-with-lease branch May 29, 2024 04:38
@ilyagr ilyagr restored the force-with-lease branch May 29, 2024 04:38
@ilyagr ilyagr deleted the force-with-lease branch May 29, 2024 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants